-
-
Notifications
You must be signed in to change notification settings - Fork 320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support concurrency limit #541
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@MadCcc 看看 |
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #541 +/- ##
==========================================
- Coverage 87.21% 82.91% -4.30%
==========================================
Files 6 7 +1
Lines 266 281 +15
Branches 72 76 +4
==========================================
+ Hits 232 233 +1
- Misses 34 48 +14 ☔ View full report in Codecov by Sentry. |
看上去得补一些用例,测试覆盖率下降了。 |
@@ -69,6 +69,7 @@ React.render(<Upload />, container); | |||
|accept | string | | input accept attribute | | |||
|capture | string | | input capture attribute | | |||
|multiple | boolean | false | only support ie10+| | |||
|concurrencyLimit | number | | asynchronously posts files with the concurrency limit | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
concurrencyLimit 的默认值是多少?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
默认值是 undefined,即不使用 concurrencyLimit
const tasks: Promise<U>[] = []; | ||
const pendings: Promise<U>[] = [] | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
多了一个空行。
src/asyncPool.ts
Outdated
|
||
if (concurrencyLimit <= items.length) { | ||
task.then(() => { | ||
pendings.splice(pendings.indexOf(task), 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
分号都补一下。
早上试了一下,xhr 请求虽然是异步的不受异步控制, |
Although `XMLHttpRequest` can asynchronously send requests, this process is implicit and cannot be awaited through `await`. To control the concurrency of `XMLHttpRequest`, it is necessary to convert `XMLHttpRequest` into an explicit asynchronous task. Modify the task completion status in both `xhr.onload` and `xhr.onerror` to enable `asyncPool` to remove completed `pending` requests through `Promise.race` and initiate the next request. To minimize code changes, add a `requestTasks` queue in the component to store `XMLHttpRequest` request tasks. Additionally, include an `appendRequestTask` parameter in the `request` function to add tasks to the queue. When the `concurrencyLimit` property is provided to the component, use `asyncPool` to control the concurrency and initiate requests. Otherwise, sequentially initiate all requests in the `requestTasks` queue.
|
方式 2 确实可能更好。 |
换种方式实现 |
relate: ant-design/ant-design#28950